<template>
   <a-modal
      title="添加工作流"
      :visible="visible"
      @ok="handleOk"
      @cancel="handleCancel"
      :confirm-loading="confirmLoading"
    >
        <a-form-model :model="formData" ref="addWorkflowForm">
            <a-form-model-item label="名称" prop="name">
                <a-input v-model="formData.name" size="large" />
            </a-form-model-item>
            <a-form-model-item label="描述" prop="description">
                <a-textarea v-model="formData.description" :rows="4" />
            </a-form-model-item>
        </a-form-model>
    </a-modal>
</template>

<script>
import {addWorkflow} from "@/api/appWorkflow"
export default {
    props:{
        visible:Boolean
    },
    data(){
        return {
            formData: {
                name: '未命名工作流',
                description: '',
                definition: null,
                appId: '',
                published: true,
            },
            confirmLoading: false
        }
    },
    methods:{
        handleOk(){
            this.$refs.addWorkflowForm.validate(async valid => {
                if (valid) {
                    this.confirmLoading = true
                    let data = await addWorkflow(this.formData)
                    this.confirmLoading = false
                    this.$emit('ok', data)
                } else {
                    return false;
                }
            });
        },
        handleCancel(){
            this.$emit('cancel')
        },
    },
    async created(){
        this.formData = {
            name: '未命名工作流',
            description: '',
            definition: null,
            appId: this.$route.params.appId || '',
            published: false,
        }
    }
}
</script>

<style>

</style>